package com.gnerv.battle.boot.framework.core.tools;


import com.gnerv.battle.boot.framework.core.exception.ParameterException;

/**
 * 分页工具
 *
 * @author Gnerv LiGen
 */
public class PageTools {

    private PageTools() {
    }

    /**
     * 分页最大1000条数据
     */
    public static final int MAX_SIZE = 1000;

    public static Integer limitStart(Integer current, Integer size) {
        if (current == null || current < 1) {
            throw new ParameterException(BattleParameterExceptionMessage.PAGE_EXCEPTION);
        }
        return (current - 1) * limitSize(size);
    }

    public static Integer limitSize(Integer size) {
        if (size == null || size < 1 || size > MAX_SIZE) {
            throw new ParameterException(BattleParameterExceptionMessage.PAGE_EXCEPTION);
        }
        return size;
    }
}
